<template>
  <div class="home">
    <HomeSwiper :banner="info.banner" />
    <div class="content" @click.once="response()">
      <div class="container">
        <div class="title">
          <div class="left">
            <h2>包装材料</h2>
            <span>PACKAGING MATERIAL</span>
          </div>
          <div class="right more">
            <router-link tag="a" target="_blank" to="/category"
              >查看更多<img src="~/assets/images/modo.png"
            /></router-link>
          </div>
        </div>
        <Panel />
        <Slide :merchant="MerchantTuiList1" />
        <div class="title">
          <div class="left">
            <h2>产品服务</h2>
            <span>PRODUCT SERVICE</span>
          </div>
          <div class="right more">
            <router-link tag="a" target="_blank" to="/industryService/service"
              >查看更多<img src="~/assets/images/modo.png" />
            </router-link>
          </div>
        </div>
        <ServicePanel />
        <Slide :merchant="MerchantTuiList2" />
        <div class="title">
          <div class="left">
            <h2>发布需求</h2>
            <span>REQUEST FOR QUOTATION</span>
          </div>
        </div>
        <div class="need-box">
          <div class="need-item">
            <div class="need-pic">
              <img src="../../assets/images/data3.png" alt="" />
            </div>
            <div class="need-desc clearfix">
              <div class="txt left">发布您的产品需求</div>
              <div class="need-into right">
                <router-link to="/require"> 进入发布 </router-link>
              </div>
            </div>
          </div>
          <div class="need-item">
            <div class="need-pic">
              <img src="../../assets/images/data4.png" alt="" />
            </div>
            <div class="need-desc clearfix trust">
              <div class="txt left">您可以将产品放心的交给我们</div>
              <div class="need-into right">
                <router-link to="official"> 委托平台 </router-link>
              </div>
            </div>
          </div>
        </div>
        <div class="title">
          <div class="left">
            <h2>官方服务</h2>
            <span>OFFICIAL SERVICE</span>
          </div>
        </div>
        <div class="office">
          <router-link target="_blank" to="/home/packmate">
            <div class="office-item">
              <div class="office-pic">
                <a>
                  <img src="../../assets/images/serviceBg1.jpg" alt="" />
                  <div class="mask"></div>
                  <div class="hover-box">
                    <ul>
                      <li>• 专业测试人员与先进实验设备</li>
                      <li>• 全球顶尖消费品公司认可</li>
                      <li>• 可测试项目高达78项等</li>
                    </ul>
                  </div>
                  <div class="desc">
                    <div class="sub-line"></div>
                    <p>找包装网拥有行先进的包装实验室，可按照企业或行业标准提供专业的包装测试服务。</p>
                    <a class="details">了解详情>></a>
                  </div>
                </a>
              </div>
              <div class="office-desc clearfix">
                <div class="txt left">包装测试</div>
                <div class="office-icon right">
                  <img src="../../assets/images/office-icon.png" alt="" />
                </div>
              </div>
            </div>
          </router-link>
          <router-link target="_blank" to="/home/packmate">
            <div class="office-item">
              <div class="office-pic">
                <a>
                  <img src="../../assets/images/serviceBg2.jpg" alt="" />
                  <div class="mask"></div>
                  <div class="hover-box">
                    <ul>
                      <li>• 平台统一培训的专业质量人员</li>
                      <li>• 极速响应与快速执行</li>
                      <li>• 质量保障，规避出货风险</li>
                    </ul>
                  </div>
                  <div class="desc">
                    <div class="sub-line"></div>
                    <p>找包装网各驻地的质量人员可进行专业、便捷、快速、低成本的验货服务。</p>
                    <a class="details">了解详情>></a>
                  </div>
                </a>
              </div>
              <div class="office-desc clearfix">
                <div class="txt left">订单验货</div>
                <div class="office-icon right">
                  <img src="../../assets/images/office-icon2.png" alt="" />
                </div>
              </div>
            </div>
          </router-link>
          <router-link target="_blank" to="/home/packmate">
            <div class="office-item">
              <div class="office-pic">
                <a>
                  <img src="../../assets/images/serviceBg3.jpg" alt="" />
                  <div class="mask"></div>
                  <div class="hover-box">
                    <ul>
                      <li>• 支持360°动态展示。</li>
                      <li>• 超高性价比，不怕产品多。</li>
                      <li>• 云端存储，便于分享展示。</li>
                    </ul>
                  </div>
                  <div class="desc">
                    <div class="sub-line"></div>
                    <p>找包装网为广大包装制造企业提供超高性价比的产品拍照解决方案。</p>
                    <a class="details">了解详情>></a>
                  </div>
                </a>
              </div>
              <div class="office-desc clearfix">
                <div class="txt left">产品拍照</div>
                <div class="office-icon right">
                  <img src="../../assets/images/office-icon3.png" alt="" />
                </div>
              </div>
            </div>
          </router-link>
          <router-link target="_blank" to="/home/packmate">
            <div class="office-item">
              <div class="office-pic">
                <a>
                  <img src="../../assets/images/serviceBg4.jpg" alt="" />
                  <div class="mask"></div>
                  <div class="hover-box">
                    <ul>
                      <li>• 确保企业真实性，避免合规风险</li>
                      <li>• 与SGS、Intertek战略合作，报告全球认可。</li>
                    </ul>
                  </div>
                  <div class="desc">
                    <div class="sub-line"></div>
                    <p>找包装网及其合作方可以根据客户或行业要求，提供验厂服务。</p>
                    <a class="details">了解详情>></a>
                  </div>
                </a>
              </div>
              <div class="office-desc clearfix">
                <div class="txt left">企业验厂</div>
                <div class="office-icon right">
                  <img src="../../assets/images/office-icon4.png" alt="" />
                </div>
              </div>
            </div>
          </router-link>
        </div>
        <div class="title">
          <div class="left">
            <h2>用户声音</h2>
            <span>USER VOICE</span>
          </div>
        </div>
        <!-- 用户声音 -->
        <UserVoice />
        <div class="title">
          <div class="left">
            <h2>新闻资讯</h2>
            <span>NEWS INFORMATION</span>
          </div>
        </div>
        <News />
      </div>
    </div>
    <Post />
    <!-- 平台提示 -->
    <loginDialog
      class="dialog"
      width="740px"
      :show-dialog.sync="showDialog1"
      title="平台提示"
    >
      <div class="dialog-content">
        <div class="dialog-item">
          <div class="dialog-icon">
            <img src="~/assets/images/bindphone.png" alt="" />
          </div>
          <div class="dialog-text">
            <p>绑定手机号</p>
            <span>请绑定与您微信一致的手机号,以便您使用手机号快捷登录</span>
          </div>
          <div v-if="hasLogin" class="dialong-btn">已完善</div>
          <div
            v-else
            class="dialong-nbtn"
            @click="$router.push({ name: 'Login' })"
          >
            立即完善
          </div>
        </div>

        <div class="dialog-item">
          <div class="dialog-icon">
            <img src="~/assets/images/bindisg.png" alt="" />
          </div>
          <div class="dialog-text">
            <p>完善个人信息</p>
            <span
              >完善个人信息后，您可以正常浏览、搜索、收藏相关产品和企业。</span
            >
          </div>
          <div
            class="dialong-nbtn"
            @click="$router.push({ name: 'PersonalSettings' })"
          >
            立即完善
          </div>
          <div class="nobind">未完善</div>
        </div>

        <div class="dialog-item">
          <div class="dialog-icon">
            <img src="~/assets/images/bindid.png" alt="" />
          </div>
          <div class="dialog-text">
            <p>实名认证</p>
            <span
              >实名认证后，您可以使用找包装网发布需求、询价、购买、查看企业联系方式等功能</span
            >
          </div>
          <div
            class="dialong-nbtn"
            @click="$router.push({ name: 'PersonalSettings' })"
          >
            立即完善
          </div>
          <div class="nobind">未完善</div>
        </div>
      </div>
    </loginDialog>
  </div>
</template>

<script>
import HomeSwiper from "./children/HomeSwiper"
import Post from "./children/Post"
import Panel from "./children/Panel"
import ServicePanel from "./children/ServicePanel"
import Slide from "./children/Slide"
import UserVoice from "./children/UserVoice"
import News from "./children/News"
import loginDialog from "./children/loginDialog"
import MButton from "@/components/common/m-button/MButton"
import { swiper, swiperSlide } from "vue-awesome-swiper"
import "swiper/dist/css/swiper.css"
import { mapMutations } from "vuex"
import Vue from "vue"
import { Tab, Tabs } from "vant"
Vue.use(Tab).use(Tabs)
import {
  getHome,
  getRecommendSerList,
  getRecommendProList,
  apiCheckBind,
  apiwxLogin
} from "@/request/api"

export default {
  name: "Home",
  components: {
    HomeSwiper,
    Post,
    ServicePanel,
    Panel,
    Slide,
    UserVoice,
    News,
    swiper,
    swiperSlide,
    loginDialog,
    MButton
  },
  data() {
    return {
      info: {
        banner: []
      },
      MerchantTuiList1: [],
      MerchantTuiList2: [],
      showDialog1: true,
      bindInfo: {}
    }
  },
  computed: {
    hasLogin() {
      return this.$store.state.hasLogin
    }
  },
  mounted() {
    this.getHomeInfo()
    this.getMerchatTui1()
    this.getMerchatTui2()
    this.getBindInfo()
    // 微信授权登录获取的code
    // console.log(this.$route, this.$route.query.code); 
  },
  watch: {
    /* $route() {
      if (this.$route.query.code != undefined) {
        console.log(this.$route,this.$route.query.code);
        this.wxLoginGetUserInfo(
          this.$route.query.code,
          this.$route.query.state
        );
      }
    } */
  },
  methods: {
    ...mapMutations(["login", "setUserInfo", "setAccessToken"]),
    wxLoginGetUserInfo() {
      const code = this.$route.query.code
      if (code) {
        apiwxLogin(code).then(res => {
          this.setUserInfo(res.data.user)
          this.setAccessToken(res.data.token)
          this.login()
          this.$toast.show("登录成功!", 1000, false)
        })
      }
    },
    // 材料精选企业
    getMerchatTui1() {
      getRecommendProList().then(res => {
        this.MerchantTuiList1 = res.data
      }).catch(err => {
        this.$message.error(err.message)
      })
    },
    getMerchatTui2() {
      getRecommendSerList().then(res => {
        this.MerchantTuiList2 = res.data
      }).catch(err => {
        this.$message.error(err.message)
      })
    },
    getHomeInfo() {
      getHome().then(res => {
        this.info = res.data
      }).catch(err => {
        this.$message.error(err.message)
      })
    },
    // 平台提示
    response() {
      if (!this.hasLogin) {
        this.showDialog1 = true
      }
    },
    getBindInfo() {
      if (this.hasLogin) {
        apiCheckBind().then(res => {
          this.bindInfo = res.data
        })
      }
    },
    cancel() {
      this.showDialog1 = false
    }
  }
};
</script>

<style scoped>
.content {
  background-color: #f5f4f9;
  padding: 50px 0;
  box-sizing: border-box;
}

.title {
  position: relative;
  z-index: 100;
}

.title::after {
  content: "";
  display: block;
  clear: both;
}

.title .left,
.title .more {
  background: #f5f4f9;
}

.title .left {
  padding-right: 12px;
}

.title .more {
  padding-left: 12px;
}

.title .left > * {
  float: left;
}

.title .left h2 {
  color: #4d4d4d;
  font-size: 26px;
  font-weight: bold;
  line-height: 34px;
}

.title .left span {
  display: inline-block;
  color: #777;
  margin-left: 12px;
  font-size: 24px;
  font-weight: bold;
  font-family: "Book Antiqua";
  line-height: 34px;
}

.title::before {
  content: "";
  display: inline-block;
  height: 6px;
  width: 100%;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: #e0e2e6;
  border-radius: 3px;
  z-index: -1;
}

.more {
  color: #e38b2e;
  margin-top: 8px;
}

.more img {
  margin-left: 5px;
}

.need-box {
  display: flex;
  margin: 30px 0 50px -38px;
}

.need-item {
  width: 680px;
  margin-left: 38px;
}

.need-item img {
  width: 100%;
  display: block;
}

.need-desc {
  height: 82px;
  line-height: 82px;
  color: #fff;
  padding: 0 20px;
  background: linear-gradient(
    30deg,
    rgb(255, 130, 95),
    rgb(255, 130, 95),
    rgb(255, 180, 98)
  );
  border-bottom-right-radius: 10px;
  border-bottom-left-radius: 10px;
}

.trust {
  background: linear-gradient(30deg, rgb(74, 149, 231), rgb(110, 196, 246));
}

.need-desc .txt {
  font-size: 24px;
  font-weight: bold;
}
.need-desc .text:hover .hover-box {
  opacity: 1;
}

.need-into {
  font-size: 16px;
  border: 1px solid #fff;
  border-radius: 10px;
  line-height: normal;
  padding: 4px 6px;
  margin-top: 28px;
}

.office {
  display: flex;
  margin: 30px 0 50px -16px;
}

.office-item {
  /* width: 345px; */
  margin-left: 16px;
}

.office-item .office-pic {
  width: 100%;
  height: 200px;
  position: relative;
}

.office-item .office-pic img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.office-item .office-pic .mask {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.45);
}

.office-item .office-pic .desc {
  position: absolute;
  top: 50px;
  left: 25px;
  color: #fff;
  padding-right: 55px;
}

.office-item .office-pic .desc .sub-line {
  width: 36px;
  height: 4px;
  background: rgb(255, 255, 255);
  margin-bottom: 27px;
}

.office-item .office-pic .desc p {
  letter-spacing: 2px;
  margin-bottom: 22px;
}

.office-item .office-desc {
  line-height: 50px;
  font-size: 16px;
  font-weight: bold;
  color: #666666;
  background: #fff;
  padding: 0 20px;
}

.office-item .office-desc .office-icon img {
  vertical-align: middle;
}
.office-item .office-desc .txt {
  cursor: pointer;
}

.topremmend {
  margin-top: 30px;
  display: flex;
  height: 60px;
  color: #fff;
  background: #e38b2e;
}

.topremmend .item {
  font-size: 16px;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.topremmend .active {
  background: #0085e8;
}

.panel-content {
  padding: 30px 22px 30px;
  background: #fff;
}

.panel-content .swiper {
  height: 634px;
  margin-left: auto;
  margin-right: auto;
  flex-wrap: wrap;
}

.panel-content .swiper-slide {
  height: 312px;
}

.panel-content .item {
  width: 100%;
  border: 1px solid #ccc;
  padding: 8px 8px 20px 8px;
}

.panel-content .item .pic-box {
  width: 100%;
  height: 167px;
}

.panel-content .item .pic-box img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.panel-content .item .item-title {
  margin: 17px 0;
  color: #333;
  height: 40px;
}

.panel-content .item .price {
  font-weight: bold;
  color: #e38b2e;
}

.panel-content .item .cart {
  margin-top: 10px;
  font-weight: bold;
  color: #e38b2e;
}

.gray {
  color: #969696;
  margin-left: 5px;
  font-weight: normal;
}

.botton-con {
  position: relative;
  margin-top: 45px;
}

.into {
  position: absolute;
  bottom: 0;
  right: 22px;
  color: #30a1d2;
  font-size: 16px;
}

.into span {
  margin-right: 14px;
}

.into img {
  vertical-align: bottom;
}

.swiper-container-multirow-column > .swiper-wrapper {
  flex-direction: row !important;
}

.pan-pagination {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

.pan-pagination >>> .swiper-pagination-bullet {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 16px;
  background: #ccc;
  opacity: 1;
  outline: none;
}

.pan-pagination >>> .swiper-pagination-bullet-active {
  background: rgba(228, 139, 44, 0.9);
  box-shadow: 0 0 10px rgba(228, 139, 44, 0.9);
}

.dialog .dialog-content {
  height: 250px;
  margin-bottom: 20px;
}

.dialog-item {
  width: 100%;
  height: 70px;
  margin-bottom: 20px;
}

.dialog-icon {
  width: 70px;
  height: 70px;
  float: left;
  margin: 0 10px;
}

.dialog-text {
  display: inline-block;
  width: 400px;
}

.dialog-text p {
  font-size: 20px;
  font-weight: bold;
  color: #666666;
}

.dialog-text span {
  font-size: 16px;
  color: #969696;
}

.dialong-btn {
  margin-top: 20px;
  width: 100px;
  height: 45px;
  float: right;
  text-align: center;
  line-height: 45px;
  font-size: 16px;
  color: #f8904a;
}

.dialong-nbtn {
  margin-top: 20px;
  width: 100px;
  height: 45px;
  float: right;
  text-align: center;
  line-height: 45px;
  border-radius: 10px;
  border: 1px solid #969696;
  cursor: pointer;
}

.nobind {
  font-size: 14px;
  color: #e44a2c;
  position: relative;
  left: 630px;
}

@media only screen and (max-width: 1200px) {
  .content {
    padding: 50px 0;
  }

  .panel-content {
    padding: 50px 20px;
  }

  .need-box {
    margin: 30px 0 50px -38px;
  }

  .office {
    margin: 30px 0 50px -16px;
  }
}

.hover-box {
  opacity: 0;
  transform: translateZ(0);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.65);
  z-index: 99;
  transition: opacity 500ms ease;
}

.hover-box ul {
  padding: 70px 30px 20px;
  color: #fff;
}

.hover-box li {
  margin: 5px 0;
  color: #fff;
  cursor: pointer;
}

.office-pic:hover .desc {
  filter: blur(2px);
  user-select: none;
}

.office-pic:hover .hover-box {
  opacity: 1;
}
.office-item:hover .hover-box {
  opacity: 1;
}
.office-item:hover .desc {
  filter: blur(5px);
  user-select: none;
}
</style>
